module ActiveDirectory
  module Schema
    module User
      include ActiveDirectory::Schema::Base
    
      def schema
        {
          :sAMAccountName =>      [ String, :public,  :username ],
          :givenName =>           [ String, :public,  :given_name ],
          :middleName =>          [ String, :public,  nil ],
          :sn =>                  [ String, :public,  :surname ],
          :displayName =>         [ String, :public,  :name ],
          :initials =>            [ String, :public,  nil ],
          :mail =>                [ String, :public,  :email ],
          :telephoneNumber =>     [ String, :public,  :main_number ],
          :mobile =>              [ String, :public,  :mobile_number ],
          :streetAddress =>       [ String, :public,  :street_address ],
          :l =>                   [ String, :public,  :city ],
          :st =>                  [ String, :public,  :state ],
          :postalCode =>          [ String, :public,  :zip ],
          :co =>                  [ String, :public,  :country ],

          :lockoutTime =>         [ String, :private, nil ],
          :userAccountControl =>  [ Fixnum, :private, nil ]
        }
      end
  
      def schema_system_attributes
        {
          :objectClass => [ 'top', 'organizationalPerson', 'person', 'user' ]
#          :objectCategory => [ 'CN=Person,CN=Configuration,' + ActiveDirectory::Base.server_settings[:base_dn] ]
        }
      end

      def primary_identifier_attribute
        'sAMAccountName'
      end

      def filter(custom_filter = nil)
        "(&(objectCategory=Person)(objectClass=User)#{custom_filter})"
      end
  
      def self.extended(parent_klass)
        ActiveDirectory::Schema.extend_with_schema(parent_klass)
      end
    end
  end
end
